<?php
// +----------------------------------------------------------------------
// | Author: 发仔 <i@fazi.me> 
// +----------------------------------------------------------------------

namespace app\unit\controller;

use think\Db;
use think\Cache;
use think\file;

class Setting extends Base
{

    //单位资质认证
    public function qualifications()
    {
        $file = request()->file('image');
        $P = input('param.');

        if($file){
            $info = $file->move(UPLOAD_PATH);
            if($info){//图片上传成功
                $company_cert_return = Db::name('company_cert')->where('company_id',session('company_id'))->select();
                if($company_cert_return){
                    $this->error('请勿重复提交');
                }
                else {
                    $data = array(
                        'company_id' => session('company_id'),
                        'image' => $info->getSaveName(),
                        'email' => $P['mail'],
                        'head' => $P['fapiaotaitou'],
                        'recognition' => $P['nashuirenshibiehao'],
                        'add' => $P['gongsizhuchedizhi'],
                        'phone' => $P['gongsizhuchedianhua'],
                        'bank_name' => $P['kaihuhangmingcheng'],
                        'bank_number' => $P['kaihuhangzhanghao']
                    );
                    Db::name('company_cert')->insert($data);
                    $company_cert_return = Db::name('company_cert')->getLastInsID();
                    if($company_cert_return){
                        $this->success('上传成功');
                    }
                }
            }else{//图片上传失败
                $this->error('图片上传失败');
            }
        }
        else{//没选图片
            $this->error('请选择图片');
        }

    }

    //单位资质认证
    public function authentication()
    {
        $company_cert_return = Db::name('company_cert')->where('company_id',session('company_id'))->select();
        if($company_cert_return){
            $this->redirect('Setting/watch_authentication', ['company_cert_id' => 16]);
        }
        else {
            return $this->out();
        }
    }

    //查看认证资料详情
    public function watch_authentication()
    {

        $list = Db::name('company_cert')->where('company_id',session('company_id'))->select();
        $company_return =  Db::name('company')->where('company_id',session('company_id'))->field('company_name')->select();

        $list[0]['name'] = $company_return[0]['company_name'];

        $this->assign('list',$list);

        return $this->out();
    }

}
